//
//  MBProgressTool.m
//  BaseLib
//
//  Created by CPX on 2018/5/23.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "MBProgressTool.h"

#define Delay 1.5

/**
 HUD封装
 @author yzl
 */
@implementation MBProgressTool

+ (MBProgressHUD*)showTextForView:(UIView *)view text:(NSString*)text{
    MBProgressHUD *hud = [MBProgressHUD HUDForView:view];
    if (!hud) {
        hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    }
    
    hud.bezelView.color = [UIColor colorWithRed:0 green:0 blue:0 alpha:.8];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.mode = MBProgressHUDModeText;
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.label.textColor = [UIColor whiteColor];
    [hud hideAnimated:YES afterDelay:Delay];
    return hud;
}

+ (MBProgressHUD*)showLoadingAndText:(UIView *)view text:(NSString *)text{
    MBProgressHUD *hud = [MBProgressHUD HUDForView:view];
    if (!hud) {
        hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    }
    
//    hud.bezelView.color = [UIColor colorWithRed:0 green:0 blue:0 alpha:.8];
//    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.label.text = text;
    hud.label.textColor = [UIColor whiteColor];
    return hud;
}

+ (MBProgressHUD*)showLoadingForView:(UIView *)view{
    MBProgressHUD *hud = [MBProgressHUD HUDForView:view];
    if (!hud) {
        hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
        UIView *v = [view viewWithTag:10000];
        if (v) {
            [hud removeFromSuperview];
            [view insertSubview:hud belowSubview:v];
        }
        
    }
//    hud.bezelView.color = [UIColor colorWithRed:0 green:0 blue:0 alpha:.8];
//    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.mode = MBProgressHUDModeIndeterminate;
    [hud showAnimated:YES];
    return hud;
}

+ (void)hideForView:(UIView *)view{
    MBProgressHUD *hud = [MBProgressHUD HUDForView:view];
    [hud hideAnimated:YES];
}

@end
